Repository navigation
PostgreSQL: Add support for DO statement - #2618
devtechedge wants to merge 3 commits into
Conversation
|
Please add examples of this syntax to the fuzzer corpus |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2618 +/- ##
=======================================
Coverage 81.14% 81.14%
=======================================
Files 42 42
Lines 33736 33766 +30
Branches 33736 33766 +30
=======================================
+ Hits 27376 27401 +25
- Misses 2797 2798 +1
- Partials 3563 3567 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
bad1741 to
0198d07
Compare
|
@LucaCappelletti94 Good call, the fuzzer should know about this syntax too. I added five seeds under Together they cover a plain fmt, clippy and the full test suite pass with them added. Happy to add or reshape any of them if you had other cases in mind 🙂 |
| Do { | ||
| /// Optional procedural language name. | ||
| language: Option<Ident>, | ||
| /// The anonymous code block, a string literal. | ||
| code: ValueWithSpan, | ||
| }, |
There was a problem hiding this comment.
Refactor this to a named struct, as every new statement variant does. I will do another review round after this refactoring as I expect most of the code will change.
| Do { | |
| /// Optional procedural language name. | |
| language: Option<Ident>, | |
| /// The anonymous code block, a string literal. | |
| code: ValueWithSpan, | |
| }, | |
| Do(DoStatement), |
There was a problem hiding this comment.
Thanks @LucaCappelletti94!
I refactored it into a named DoStatement struct (Statement::Do(DoStatement)), with its own Display and From<DoStatement> for Statement, following the pattern of the other statement structs.
I also gave it a Spanned impl covering the language and code block, with a small span test.
Parsing behavior and existing tests are unchanged, and fmt, clippy and the full test suite pass.
Ready for another look whenever you have time.
f58b626 to
adc68d1
Compare
DOblocks likeDO $$BEGIN RAISE NOTICE 'hi'; END$$currently fail with "Expected: an SQL statement, found: DO".This adds
Statement::Do { language, code }for PostgreSQL'sDOstatement, gated behind a newDialect::supports_do_statement()that is enabled for PostgreSQL.The code block must be a string literal (single-quoted, dollar-quoted, or
E''), andLANGUAGE langis accepted either before or after it, as the PostgreSQL grammar allows.Display normalizes to the documented
DO [ LANGUAGE lang ] codeorder, and a repeatedLANGUAGEis rejected.Tests in
tests/sqlparser_common.rscover both orders, the round trip, the error cases, and dialects without support.The implementation and tests were drafted with an AI coding assistant (Grok 4.7 effort: xHigh), and I reviewed the diff, ran the test suite and the fuzzer, and stand by the change.
Fixes #2609